<?php

namespace app\admin\controller;

use app\common\controller\Backend;
use think\helper\Time;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class ReserveRecord extends Backend
{
    
    /**
     * TracePosition模型对象
     * @var \app\admin\model\TracePosition
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\ReserveRecord;

    }
    
    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */
    

    public function index()
    {
        
        $filter = json_decode(input('filter'),true);

        $where_ = [];

        
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            // if ($this->request->request('keyField')) {
            //     return $this->selectpage();
            // }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

                   
            if(isset($filter['username']) && $filter['username']){
                $where_['nickname'] = ['like','%'.$filter['username'].'%'];
            }
            if(isset($filter['sid']) && $filter['sid']){
                $where_['sid'] = ['like','%'.$filter['sid'].'%'];
            }


            $total = $this->model
                // -> alias('a')
                //-> where($mimetypeQuery)
                // -> where($this -> whereType)
                // -> whereNotIn('a.id',$reported)
                ->where($where_)
                // ->join('department b','b.id=a.department_id')
                // ->join('college c','c.id=b.college_id')
                // ->field('nickname,tel,b.name as department_name ,c.name as college_name')
                ->order('id','desc')
                ->count();

            $list = $this->model
                // -> alias('a')
                //-> where($mimetypeQuery)
                // -> where($this -> whereType)
                // -> whereNotIn('a.id',$reported)
                ->where($where_)
                // ->join('department b','b.id=a.department_id')
                // ->join('college c','c.id=b.college_id')
                // ->field('nickname,tel,b.name as department_name ,c.name as college_name')
                ->order('id','desc')
                ->limit($offset, $limit)
                ->select();

            $list = collection($list)->toArray();
            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }

        
        //统计
        // $where_['id'] = 1;
        // $reserve = (new \app\admin\model\ReserveSetting()) -> alias('rs')->where($where_) -> find();

        // //预约成功人数
        // $where ['states']=1;
        // $allcount = (new \app\admin\model\ReserveRecord()) -> alias('rr')->where($where) -> count();

        // //预约过期人数
        // $whered['states']=2;
        // $allcounted = (new \app\admin\model\ReserveRecord()) -> alias('rr')->where($whered) -> count();

        // //进入图书馆人数
        // $where_into['into_states']=1;
        // $into_count = (new \app\admin\model\ReserveRecord()) -> alias('rr')->where($where_into) -> count();

        // //已离开图书馆人数
        // $where_leave['leave_states']=1;
        // $leave_count = (new \app\admin\model\ReserveRecord()) -> alias('rr')->where($where_leave) -> count();



        // $today = Time::today();
        // $todayStr = date("Y-m-d H:i:s",$today[0]).' - '.date("Y-m-d H:i:s",$today[1]);
        // $this->assign('today', $todayStr);


        // $this -> assign('allcount',$allcount);
        // $this -> assign('allcounted',$allcounted);
        // $this -> assign('reserve',$reserve);
        // $this -> assign('into_count',$into_count);
        // $this -> assign('leave_count',$leave_count);

        return $this->view->fetch();
    }

}
